package com.hnevc.xiaoming.shijianactivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.hnevc.xiaoming.R;

public class FocusActivity extends AppCompatActivity {

    private FrameLayout ly1;
    private FrameLayout ly2;
    private Button btn_focs;
    private TextView view_text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_focus);
        initView();
        initEvent();
    }

    private void initEvent() {

        ly1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
//                Toast.makeText(FocusActivity.this, "", Toast.LENGTH_SHORT).show();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        view_text.setText("你选择了L2");
                    }
                });
            }
        });
        ly2.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        view_text.setText("你选择了L2");
                    }
                });
            }
        });
        btn_focs.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        view_text.setText("你选择了L2");
                    }
                });

            }
        });


    }

    private void initView() {
        ly1 = findViewById(R.id.ly1);
        ly2 = findViewById(R.id.ly2);
        btn_focs = (Button) findViewById(R.id.btn_focs);
        view_text = (TextView) findViewById(R.id.view_text);

    }


}